using MediatR;
using MeetingManagement.Domain.Entities;
using MeetingManagement.Domain.Repositories;

namespace MeetingManagement.Application.Commands.MeetingRooms.UpdateMeetingRoom
{
    public class UpdateMeetingRoomCommandHandler : IRequestHandler<UpdateMeetingRoomCommand, bool>
    {
        private readonly IRepository<MeetingRoom> _repository;
        public UpdateMeetingRoomCommandHandler(IRepository<MeetingRoom> repository)
        {
            _repository = repository;
        }

        public async Task<bool> Handle(UpdateMeetingRoomCommand request, CancellationToken cancellationToken)
        {
            var room = _repository.Get(request.Id);
            if (room == null) return false;
            room.Update(request.Name, request.Location, request.Capacity, request.HasProjector, request.HasWhiteboard, request.HasVideoConference, request.Description);
            await _repository.UpdateAsync(room);
            return true;
        }
    }
}
